package com.sushi.utils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;

/**
 * 列表相关 工具类
 * @author Administrator
 */
public class CollectionUtil {

    /**
     * 倒置列表  ArrayList
     */
    public static ArrayList<?> reverse(ArrayList<?> arrayList) {
        ArrayList<Object> ans = new ArrayList<>();
        arrayList.forEach(element -> ans.add(0, element));
        return ans;
    }
    /**
     * 倒置列表  LinkedList
     */
    public static LinkedList<?> reverse(LinkedList<?> linkedList) {
        LinkedList<Object> ans = new LinkedList<>();
        linkedList.forEach(node -> ans.add(0, node));
        return ans;
    }

    /**
     * 判空
     */
    public static boolean isEmpty(Collection<?> collection) {
        if (null == collection) {
            return true;
        }
        return collection.size() == 0;
    }

    /**
     * 判非空
     */
    public static boolean isNotEmpty(Collection<?> collection) {
        return !isEmpty(collection);
    }

}
